package com.dap.oss.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 *  OSS配置注解类
 */
@Component
public class OSSConfig {
	
	@Value("${oss.endpoint}")
	private String endpoint;
	
	@Value("${oss.accessKeyId}")
	private String accessKeyId;
	
	@Value("${oss.accessKeySecret}")
	private String accessKeySecret;
	/**查看地址*/
	@Value("${oss.img.url}")
	private String imgUrl;
	@Value("${oss.bucket}")
    private String bucket;


	public String resolveFullUrl(String fileName) {
		return "https://" + bucket + imgUrl + fileName;
	}
	public String resolveFileNameFromFullUrl(String fullUrl) {
		int index = fullUrl.indexOf(imgUrl);
		if (index < 0) {
			return null;
		}
		index += imgUrl.length();

		return fullUrl.substring(index);
	}
	

	public String getEndpoint() {
		return endpoint;
	}

	public void setEndpoint(String endpoint) {
		this.endpoint = endpoint;
	}

	public String getAccessKeyId() {
		return accessKeyId;
	}

	public void setAccessKeyId(String accessKeyId) {
		this.accessKeyId = accessKeyId;
	}

	public String getAccessKeySecret() {
		return accessKeySecret;
	}

	public void setAccessKeySecret(String accessKeySecret) {
		this.accessKeySecret = accessKeySecret;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

    public String getBucket() {
        return bucket;
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }
}